package com.asin;

import com.asin.mapper.UserMapper;
import com.asin.pojo.Order;
import com.asin.pojo.Role;
import com.asin.pojo.User;
import com.asin.util.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class testMybatis {



    @Test
    public void testFindUserAndInfoById(){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User userAndInfoById = mapper.findUserAndInfoById(1);
        System.out.println("userAndInfoById = " + userAndInfoById);
        sqlSession.close();

    }
    @Test
    public void testFindUserAndOrders(){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User userAndOrders = mapper.findUserAndOrders(1);
        List<Order> orders = userAndOrders.getOrders();
        for (Order order : orders) {
            System.out.println("order = " + order);
        }
        sqlSession.close();

    }
    @Test
    public void testFindUserAndRoles(){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User userAndRoles = mapper.findUserAndRoles(1);
        List<Role> roles = userAndRoles.getRoles();
        for (Role r : roles) {
            System.out.println("r = " + r);
        }
        sqlSession.close();

    }
    @Test
    public void test01(){


    }


}
